{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Solution:\n",
    "    def plusOne(self, digits: [int]) -> [int]:\n",
    "        # Remove leading zero\n",
    "        i = 0\n",
    "        while i < len(digits) and digits[i] == 0:\n",
    "            i = i + 1\n",
    "        # if [0,] return [1]\n",
    "        if i == len(digits):\n",
    "            return [1]\n",
    "        # Plus one\n",
    "        i = len(digits) - 1\n",
    "        digits[i] = digits[i] + 1\n",
    "        # process placement\n",
    "        while i > 0 and digits[i] > 9:\n",
    "            digits[i-1] = digits[i-1] + 1\n",
    "            digits[i] = digits[i] - 10\n",
    "            i = i - 1\n",
    "        if digits[0] > 9:\n",
    "            digits = [1, 0] + digits[1:]\n",
    "        return digits"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[2, 0, 0]"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = Solution()\n",
    "s.plusOne([1,9,9])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "py3",
   "language": "python",
   "name": "py3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
